<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Models\login;
class LoginController extends Controller
{   
	//登陆页面
    public function login()
    {
    	return view("admin.login");
    }

    //执行登陆
    public function doLogin(Request $request)
    {
        
    	$username = $request->username;
    	$password = md5($request->password);
    	$model = new Login();
       
        // $user = DB::table("user")->where("name",$username)->first();
    	$user = $model->doLogin($username);
        // dd($model);die;
    	if(!empty($user)){
    		if($user->password == $password){
    			session()->put("username",$user);
    			return redirect("admin");
    		}else{
    			return back()->with("msg","用户名或密码不存在");
    		}
    	}else{
    		return back()->with("msg","用户名不存在");
    	}
     }
}
